package com.ds.web.ctrl;

import com.ds.base.msg.BrandFilingMsg;
import com.ds.base.msg.CargoFilingMsg;
import com.ds.base.msg.CompanyFilingMsg;
import com.ds.base.utils.CBTUtil;
import com.ds.persist.vo.http.RespModel;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 备案
 *
 * @author zhangyou
 * @date 2018/12/2
 */
@RestController
public class FilingCtrl {


    /**
     * 品牌备案
     *
     * @param brandFilingMsg
     */
    @PostMapping(value = "/brand/filing")
    public void brandFiling(@RequestBody BrandFilingMsg brandFilingMsg) {
        CBTUtil.sendMsg(brandFilingMsg);
    }


    /**
     * 商品备案
     *
     * @param cargoFilingMsg
     */
    @PostMapping(value = "/cargo/filing")
    public JSONObject cargoFiling(@Valid @RequestBody CargoFilingMsg cargoFilingMsg, BindingResult br) {
        RespModel respModel = new RespModel();
        if (br.hasErrors()) {
            respModel.addError(br);
            return respModel.toJSON();
        }
        JSONObject jsonObject = CBTUtil.sendMsg(cargoFilingMsg);
        System.out.println(jsonObject.toString());
        respModel.setData(jsonObject);
        return respModel.toJSON();
    }


    /**
     * 企业备案
     *
     * @param companyFilingMsg
     */
    @PostMapping(value = "/company/filing")
    public JSONObject companyFiling(@Valid @RequestBody CompanyFilingMsg companyFilingMsg,
                                    BindingResult br
    ) {
        RespModel respModel = new RespModel();
        if (br.hasErrors()) {
            respModel.addError(br);
            return respModel.toJSON();
        }
        JSONObject jsonObject = CBTUtil.sendMsg(companyFilingMsg);
        System.out.println(jsonObject.toString());
        respModel.setData(jsonObject);
        return respModel.toJSON();
    }


}
